package cn.com.duiba.millionaire.center.controller;

import cn.com.duiba.millionaire.center.spider.common.DuiBaSpider;
import cn.com.duiba.millionaire.center.spider.spdierjob.Pc6SpiderJob;
import cn.com.duiba.millionaire.center.spider.spdierjob.XiaoMiAppSpiderJob;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutorService;

/**
 * Created by sunchangji on 2018/6/12.
 */
@RestController
@RequestMapping("/app")
public class Pc6AppSoiderController {

    private static String[] pc6Urls = new String[]{
            "http://www.pc6.com/android/588_1.html",
            "http://www.pc6.com/android/589_1.html",
            "http://www.pc6.com/android/584_1.html",
            "http://www.pc6.com/android/582_1.html",
            "http://www.pc6.com/android/583_1.html",
            "http://www.pc6.com/android/585_1.html",
            "http://www.pc6.com/android/586_1.html",
            "http://www.pc6.com/android/587_1.html",
            "http://www.pc6.com/android/600_1.html",
            "http://www.pc6.com/android/qq_703_1.html",
            "http://www.pc6.com/android/qq_704_1.html",
            "http://www.pc6.com/android/qq_708_1.html",
            "http://www.pc6.com/android/qq_709_1.html",
            "http://www.pc6.com/android/875_1.html",
            "http://www.pc6.com/android/876_1.html",
            "http://www.pc6.com/android/877_1.html",
            "http://www.pc6.com/android/878_1.html",
            "http://www.pc6.com/android/879_1.html",
            "http://www.pc6.com/android/880_1.html",
            "http://www.pc6.com/android/881_1.html",
            "http://www.pc6.com/android/628_1.html",
            "http://www.pc6.com/android/qq_705_1.html",
            "http://www.pc6.com/android/qq_706_1.html",
            "http://www.pc6.com/android/627_1.html",
            "http://www.pc6.com/android/599_1.html"

    };

    //小米应用数据
    private static final String PAGE_URL = "http://app.mi.com/categotyAllListApi?categoryId={0}&pageSize=30&page=0";
    private static List<String> categoryIds = Lists.newArrayList(
            "15",//游戏
            "5",//实用工具
            "27",//影音视听
            "2",//聊天社交
            "7",//图书阅读
            "12",//学习教育
            "10",//效率办公
            "9",//时尚购物
            "4",//居家生活
            "3",//旅行交通
            "6",//摄影摄像
            "14",//医疗健康
            "8",//体育运动
            "11",//查看全部新闻资讯
            "13",//娱乐消遣
            "1"//金融理财

    );

    @Autowired
    private Pc6SpiderJob pc6SpiderJob;
    @Autowired
    private XiaoMiAppSpiderJob xiaoMiAppSpiderJob;
    @Autowired
    private ExecutorService executorService;


    @GetMapping("/pc6/run")
    public String startPc6StartSpiderJob() {
        executorService.execute(() ->
                DuiBaSpider.builder()
                        .setStartURL(pc6Urls)
                        .setName("pc6")
                        .setPageConsumer(pc6SpiderJob.pageConsumer)
                        .build()
                        .run()
        );

        return "启动完毕";
    }
}
